"""
合并大文件 按行转移到一个文件中
"""
import os
import shutil
import sys
import time

import click

cur_dir_fullpath = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.abspath(os.path.join(cur_dir_fullpath, '../../')))  # 插入
from xjlibrary.configread import MyConfigParser
from xjlibrary.our_file_dir import BaseDir
from xjlibrary.tools.BaseFile_giveup import BaseFile, AddFileAB


def start(filePath, output):
    if not os.path.exists(output):
        os.makedirs(output)
    outputFile = BaseFile.getNewPath(output, "all.big_html")
    for fLine in BaseDir.read_file_r_mode_yield(filePath):
        if fLine.strip():
            BaseDir.single_add_file(outputFile,fLine+"\n")
    # shutil.move(filePath, output)
    print("合并成功")



def main(inputs, output, config):
        for filePath in BaseDir.get_dir_all_files(inputs):
            print("开始合并:" + filePath)
            start(filePath, output)


if __name__ == "__main__":
    inputs = r"D:\download\jstorbook\download\book"
    output = r"D:\download\jstorbook\download\book2"
    main(inputs, output, "")
